package operation;

import java.nio.file.attribute.AclEntryFlag;
import java.util.ArrayList;
import java.util.Objects;

public class shoppingCar {
    private ArrayList<purchase> purchaseList;
    private final int Limit=999;
    private int number;
    public Boolean isOverweightOf(){
        return number >= Limit;
    }
    public shoppingCar(){
        this.purchaseList = new ArrayList<>();
    }
    public Boolean add(purchase good){
        boolean idx = true;
        if(good.getAmount() + number >= Limit){
            System.out.println("您的购物车已满！");
            idx = false;
        }else{
            purchaseList.add(good);
            number += good.getAmount();
            System.out.println("添加成功");
            idx = true;
        }
        return idx;
    }
    public Boolean delete(String name){
        System.out.println("请输入你要删除的商品名称");
        for (purchase good:purchaseList) {
            if(Objects.equals(name,good.getWay().getName())){
                purchaseList.remove(good);
                number -= good.getAmount();
                System.out.println("删除成功！");
                return true;
            }
        }
        return false;
    }
    public int check(){
        int result = 0;
        for (purchase good:purchaseList) {
            result += good.getAmount() * good.getWay().getPrice();
        }
        return result;
    }
    public void show(){
        for (purchase good:purchaseList) {
            System.out.println(good.toString());
        }
    }

}
